<?php

namespace App\Http\Requests\School;

use App\Models\BookOrder;
use Illuminate\Foundation\Http\FormRequest;

/**
 * Class SettleBookRule
 * @package App\Http\Requests\School
 * 结算订餐规则
 */
class SettleBookRule extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => function ($attribute, $value, $fail) {
                if (BookOrder::isNotCanceled()->where('school_id', \Auth::user()->school_id)->where('book_rule_id', $value)->count() <= 0) {
                    return $fail('未找到应用该订餐规则的订单');
                }
            }
        ];
    }

    /**
     * @return array
     */
    public function attributes()
    {
        return [];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [];
    }
}
